home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / fileutil.13 / fileutil / fileutils-3.13 / lib / getdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-06  |  48.6 KB  |  1,936 lines

  1.  
  2. /*  A Bison parser, made from ./getdate.y
  3.  by  GNU Bison version 1.25
  4.   */
  5.  
  6. #define YYBISON 1  /* Identify Bison output.  */
  7.  
  8. #define    tAGO    258
  9. #define    tDAY    259
  10. #define    tDAYZONE    260
  11. #define    tID    261
  12. #define    tMERIDIAN    262
  13. #define    tMINUTE_UNIT    263
  14. #define    tMONTH    264
  15. #define    tMONTH_UNIT    265
  16. #define    tSEC_UNIT    266
  17. #define    tSNUMBER    267
  18. #define    tUNUMBER    268
  19. #define    tZONE    269
  20. #define    tDST    270
  21.  
  22. #line 1 "./getdate.y"
  23.  
  24. /*
  25. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  26. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  27. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  28. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  29. **  send any email to Rich.
  30. **
  31. **  This grammar has 10 shift/reduce conflicts.
  32. **
  33. **  This code is in the public domain and has no copyright.
  34. */
  35. /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
  36. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  37.  
  38. #ifdef HAVE_CONFIG_H
  39. #include <config.h>
  40.  
  41. #ifdef FORCE_ALLOCA_H
  42. #include <alloca.h>
  43. #endif
  44. #endif
  45.  
  46. /* Since the code of getdate.y is not included in the Emacs executable
  47.    itself, there is no need to #define static in this file.  Even if
  48.    the code were included in the Emacs executable, it probably
  49.    wouldn't do any harm to #undef it here; this will only cause
  50.    problems if we try to write to a static variable, which I don't
  51.    think this code needs to do.  */
  52. #ifdef emacs
  53. #undef static
  54. #endif
  55.  
  56. #include <stdio.h>
  57. #include <ctype.h>
  58.  
  59. #if    defined (vms)
  60. #include <types.h>
  61. #include <time.h>
  62. #else
  63. #include <sys/types.h>
  64. #ifdef TIME_WITH_SYS_TIME
  65. #include <sys/time.h>
  66. #include <time.h>
  67. #else
  68. #ifdef HAVE_SYS_TIME_H
  69. #include <sys/time.h>
  70. #else
  71. #include <time.h>
  72. #endif
  73. #endif
  74.  
  75. #ifdef timezone
  76. #undef timezone /* needed for sgi */
  77. #endif
  78.  
  79. #if defined (HAVE_SYS_TIMEB_H)
  80. #include <sys/timeb.h>
  81. #else
  82.  
  83. /* get_date uses the obsolete `struct timeb' in its interface!  FIXME.
  84.    Since some systems don't have it, we define it here;
  85.    callers must do likewise.  */
  86. struct timeb
  87.   {
  88.     time_t        time;        /* Seconds since the epoch    */
  89.     unsigned short    millitm;    /* Field not used        */
  90.     short        timezone;    /* Minutes west of GMT        */
  91.     short        dstflag;    /* Field not used        */
  92. };
  93. #endif /* defined (HAVE_SYS_TIMEB_H) */
  94.  
  95. #endif    /* defined (vms) */
  96.  
  97. #if defined (STDC_HEADERS) || defined (USG)
  98. #include <string.h>
  99. #endif
  100.  
  101. /* Some old versions of bison generate parsers that use bcopy.
  102.    That loses on systems that don't provide the function, so we have
  103.    to redefine it here.  */
  104. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  105. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  106. #endif
  107.  
  108. extern struct tm    *gmtime ();
  109. extern struct tm    *localtime ();
  110.  
  111. #define yyparse getdate_yyparse
  112. #define yylex getdate_yylex
  113. #define yyerror getdate_yyerror
  114.  
  115. static int yylex ();
  116. static int yyerror ();
  117.  
  118. #define EPOCH        1970
  119. #define DOOMSDAY    2038
  120. #define HOUR(x)        ((time_t)(x) * 60)
  121. #define SECSPERDAY    (24L * 60L * 60L)
  122.  
  123. #define MAX_BUFF_LEN    128   /* size of buffer to read the date into */
  124.  
  125. /*
  126. **  An entry in the lexical lookup table.
  127. */
  128. typedef struct _TABLE {
  129.     const char    *name;
  130.     int        type;
  131.     time_t    value;
  132. } TABLE;
  133.  
  134.  
  135. /*
  136. **  Daylight-savings mode:  on, off, or not yet known.
  137. */
  138. typedef enum _DSTMODE {
  139.     DSTon, DSToff, DSTmaybe
  140. } DSTMODE;
  141.  
  142. /*
  143. **  Meridian:  am, pm, or 24-hour style.
  144. */
  145. typedef enum _MERIDIAN {
  146.     MERam, MERpm, MER24
  147. } MERIDIAN;
  148.  
  149.  
  150. /*
  151. **  Global variables.  We could get rid of most of these by using a good
  152. **  union as the yacc stack.  (This routine was originally written before
  153. **  yacc had the %union construct.)  Maybe someday; right now we only use
  154. **  the %union very rarely.
  155. */
  156. static char    *yyInput;
  157. static DSTMODE    yyDSTmode;
  158. static time_t    yyDayOrdinal;
  159. static time_t    yyDayNumber;
  160. static int    yyHaveDate;
  161. static int    yyHaveDay;
  162. static int    yyHaveRel;
  163. static int    yyHaveTime;
  164. static int    yyHaveZone;
  165. static time_t    yyTimezone;
  166. static time_t    yyDay;
  167. static time_t    yyHour;
  168. static time_t    yyMinutes;
  169. static time_t    yyMonth;
  170. static time_t    yySeconds;
  171. static time_t    yyYear;
  172. static MERIDIAN    yyMeridian;
  173. static time_t    yyRelMonth;
  174. static time_t    yyRelSeconds;
  175.  
  176.  
  177. #line 156 "./getdate.y"
  178. typedef union {
  179.     time_t        Number;
  180.     enum _MERIDIAN    Meridian;
  181. } YYSTYPE;
  182. #include <stdio.h>
  183.  
  184. #ifndef __cplusplus
  185. #ifndef __STDC__
  186. #define const
  187. #endif
  188. #endif
  189.  
  190.  
  191.  
  192. #define    YYFINAL        52
  193. #define    YYFLAG        -32768
  194. #define    YYNTBASE    19
  195.  
  196. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  197.  
  198. static const char yytranslate[] = {     0,
  199.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  200.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  201.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  202.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  203.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  204.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  205.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  206.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  207.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  208.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  209.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  210.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  211.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  212.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  213.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  214.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  215.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  216.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  217.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  218.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  219.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  220.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  221.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  222.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  223.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  224.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  225.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  226. };
  227.  
  228. #if YYDEBUG != 0
  229. static const short yyprhs[] = {     0,
  230.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  231.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  232.     62,    68,    72,    76,    79,    84,    87,    91,    94,    96,
  233.     99,   102,   104,   107,   110,   112,   115,   118,   120,   122,
  234.    123
  235. };
  236.  
  237. static const short yyrhs[] = {    -1,
  238.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  239.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  240.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  241.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  242.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  243.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  244.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  245.      0,    13,     9,    12,     0,     9,    13,     0,     9,    13,
  246.     17,    13,     0,    13,     9,     0,    13,     9,    13,     0,
  247.     26,     3,     0,    26,     0,    13,     8,     0,    12,     8,
  248.      0,     8,     0,    12,    11,     0,    13,    11,     0,    11,
  249.      0,    12,    10,     0,    13,    10,     0,    10,     0,    13,
  250.      0,     0,     7,     0
  251. };
  252.  
  253. #endif
  254.  
  255. #if YYDEBUG != 0
  256. static const short yyrline[] = { 0,
  257.    170,   171,   174,   177,   180,   183,   186,   189,   192,   198,
  258.    204,   211,   217,   227,   231,   235,   242,   246,   250,   256,
  259.    260,   265,   271,   277,   281,   286,   290,   297,   301,   304,
  260.    307,   310,   313,   316,   319,   322,   325,   328,   333,   360,
  261.    363
  262. };
  263. #endif
  264.  
  265.  
  266. #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
  267.  
  268. static const char * const yytname[] = {   "$","error","$undefined.","tAGO","tDAY",
  269. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  270. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  271. "zone","day","date","rel","relunit","number","o_merid", NULL
  272. };
  273. #endif
  274.  
  275. static const short yyr1[] = {     0,
  276.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  277.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  278.     24,    24,    24,    24,    24,    24,    24,    25,    25,    26,
  279.     26,    26,    26,    26,    26,    26,    26,    26,    27,    28,
  280.     28
  281. };
  282.  
  283. static const short yyr2[] = {     0,
  284.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  285.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  286.      5,     3,     3,     2,     4,     2,     3,     2,     1,     2,
  287.      2,     1,     2,     2,     1,     2,     2,     1,     1,     0,
  288.      1
  289. };
  290.  
  291. static const short yydefact[] = {     1,
  292.      0,    17,    15,    32,     0,    38,    35,     0,    39,    14,
  293.      2,     3,     4,     6,     5,     7,    29,     8,    18,    24,
  294.     31,    36,    33,    19,     9,    30,    26,    37,    34,     0,
  295.      0,     0,    16,    28,     0,    23,    27,    22,    40,    20,
  296.     25,    41,    11,     0,    10,     0,    40,    21,    13,    12,
  297.      0,     0
  298. };
  299.  
  300. static const short yydefgoto[] = {     1,
  301.     11,    12,    13,    14,    15,    16,    17,    18,    45
  302. };
  303.  
  304. static const short yypact[] = {-32768,
  305.      0,    -1,-32768,-32768,     4,-32768,-32768,    25,    11,    -8,
  306. -32768,-32768,-32768,-32768,-32768,-32768,    21,-32768,-32768,     9,
  307. -32768,-32768,-32768,-32768,-32768,-32768,   -10,-32768,-32768,    16,
  308.     19,    24,-32768,-32768,    26,-32768,-32768,-32768,    18,    13,
  309. -32768,-32768,-32768,    27,-32768,    28,    -6,-32768,-32768,-32768,
  310.     38,-32768
  311. };
  312.  
  313. static const short yypgoto[] = {-32768,
  314. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  315. };
  316.  
  317.  
  318. #define    YYLAST        42
  319.  
  320.  
  321. static const short yytable[] = {    51,
  322.     42,    36,    37,     2,     3,    49,    33,     4,     5,     6,
  323.      7,     8,     9,    10,    24,    19,    20,    25,    26,    27,
  324.     28,    29,    30,    34,    42,    35,    31,    38,    32,    43,
  325.     46,    39,    21,    44,    22,    23,    40,    52,    41,    47,
  326.     48,    50
  327. };
  328.  
  329. static const short yycheck[] = {     0,
  330.      7,    12,    13,     4,     5,    12,    15,     8,     9,    10,
  331.     11,    12,    13,    14,     4,    17,    13,     7,     8,     9,
  332.     10,    11,    12,     3,     7,    17,    16,    12,    18,    12,
  333.     18,    13,     8,    16,    10,    11,    13,     0,    13,    13,
  334.     13,    47
  335. };
  336. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  337. #line 3 "/p/share/bison.simple"
  338.  
  339. /* Skeleton output parser for bison,
  340.    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
  341.  
  342.    This program is free software; you can redistribute it and/or modify
  343.    it under the terms of the GNU General Public License as published by
  344.    the Free Software Foundation; either version 2, or (at your option)
  345.    any later version.
  346.  
  347.    This program is distributed in the hope that it will be useful,
  348.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  349.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  350.    GNU General Public License for more details.
  351.  
  352.    You should have received a copy of the GNU General Public License
  353.    along with this program; if not, write to the Free Software
  354.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  355.  
  356. /* As a special exception, when this file is copied by Bison into a
  357.    Bison output file, you may use that output file without restriction.
  358.    This special exception was added by the Free Software Foundation
  359.    in version 1.24 of Bison.  */
  360.  
  361. #ifndef alloca
  362. #ifdef __GNUC__
  363. #define alloca __builtin_alloca
  364. #else /* not GNU C.  */
  365. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  366. #include <alloca.h>
  367. #else /* not sparc */
  368. #if defined (MSDOS) && !defined (__TURBOC__)
  369. #include <malloc.h>
  370. #else /* not MSDOS, or __TURBOC__ */
  371. #if defined(_AIX)
  372. #include <malloc.h>
  373.  #pragma alloca
  374. #else /* not MSDOS, __TURBOC__, or _AIX */
  375. #ifdef __hpux
  376. #ifdef __cplusplus
  377. extern "C" {
  378. void *alloca (unsigned int);
  379. };
  380. #else /* not __cplusplus */
  381. void *alloca ();
  382. #endif /* not __cplusplus */
  383. #endif /* __hpux */
  384. #endif /* not _AIX */
  385. #endif /* not MSDOS, or __TURBOC__ */
  386. #endif /* not sparc.  */
  387. #endif /* not GNU C.  */
  388. #endif /* alloca not defined.  */
  389.  
  390. /* This is the parser code that is written into each bison parser
  391.   when the %semantic_parser declaration is not specified in the grammar.
  392.   It was written by Richard Stallman by simplifying the hairy parser
  393.   used when %semantic_parser is specified.  */
  394.  
  395. /* Note: there must be only one dollar sign in this file.
  396.    It is replaced by the list of actions, each action
  397.    as one case of the switch.  */
  398.  
  399. #define yyerrok        (yyerrstatus = 0)
  400. #define yyclearin    (yychar = YYEMPTY)
  401. #define YYEMPTY        -2
  402. #define YYEOF        0
  403. #define YYACCEPT    return(0)
  404. #define YYABORT     return(1)
  405. #define YYERROR        goto yyerrlab1
  406. /* Like YYERROR except do call yyerror.
  407.    This remains here temporarily to ease the
  408.    transition to the new meaning of YYERROR, for GCC.
  409.    Once GCC version 2 has supplanted version 1, this can go.  */
  410. #define YYFAIL        goto yyerrlab
  411. #define YYRECOVERING()  (!!yyerrstatus)
  412. #define YYBACKUP(token, value) \
  413. do                                \
  414.   if (yychar == YYEMPTY && yylen == 1)                \
  415.     { yychar = (token), yylval = (value);            \
  416.       yychar1 = YYTRANSLATE (yychar);                \
  417.       YYPOPSTACK;                        \
  418.       goto yybackup;                        \
  419.     }                                \
  420.   else                                \
  421.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  422. while (0)
  423.  
  424. #define YYTERROR    1
  425. #define YYERRCODE    256
  426.  
  427. #ifndef YYPURE
  428. #define YYLEX        yylex()
  429. #endif
  430.  
  431. #ifdef YYPURE
  432. #ifdef YYLSP_NEEDED
  433. #ifdef YYLEX_PARAM
  434. #define YYLEX        yylex(&yylval, &yylloc, YYLEX_PARAM)
  435. #else
  436. #define YYLEX        yylex(&yylval, &yylloc)
  437. #endif
  438. #else /* not YYLSP_NEEDED */
  439. #ifdef YYLEX_PARAM
  440. #define YYLEX        yylex(&yylval, YYLEX_PARAM)
  441. #else
  442. #define YYLEX        yylex(&yylval)
  443. #endif
  444. #endif /* not YYLSP_NEEDED */
  445. #endif
  446.  
  447. /* If nonreentrant, generate the variables here */
  448.  
  449. #ifndef YYPURE
  450.  
  451. int    yychar;            /*  the lookahead symbol        */
  452. YYSTYPE    yylval;            /*  the semantic value of the        */
  453.                 /*  lookahead symbol            */
  454.  
  455. #ifdef YYLSP_NEEDED
  456. YYLTYPE yylloc;            /*  location data for the lookahead    */
  457.                 /*  symbol                */
  458. #endif
  459.  
  460. int yynerrs;            /*  number of parse errors so far       */
  461. #endif  /* not YYPURE */
  462.  
  463. #if YYDEBUG != 0
  464. int yydebug;            /*  nonzero means print parse trace    */
  465. /* Since this is uninitialized, it does not stop multiple parsers
  466.    from coexisting.  */
  467. #endif
  468.  
  469. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  470.  
  471. #ifndef    YYINITDEPTH
  472. #define YYINITDEPTH 200
  473. #endif
  474.  
  475. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  476.     (effective only if the built-in stack extension method is used).  */
  477.  
  478. #if YYMAXDEPTH == 0
  479. #undef YYMAXDEPTH
  480. #endif
  481.  
  482. #ifndef YYMAXDEPTH
  483. #define YYMAXDEPTH 10000
  484. #endif
  485.  
  486. /* Prevent warning if -Wstrict-prototypes.  */
  487. #ifdef __GNUC__
  488. int yyparse (void);
  489. #endif
  490.  
  491. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  492. #define __yy_memcpy(TO,FROM,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  493. #else                /* not GNU C or C++ */
  494. #ifndef __cplusplus
  495.  
  496. /* This is the most reliable way to avoid incompatibilities
  497.    in available built-in functions on various systems.  */
  498. static void
  499. __yy_memcpy (to, from, count)
  500.      char *to;
  501.      char *from;
  502.      int count;
  503. {
  504.   register char *f = from;
  505.   register char *t = to;
  506.   register int i = count;
  507.  
  508.   while (i-- > 0)
  509.     *t++ = *f++;
  510. }
  511.  
  512. #else /* __cplusplus */
  513.  
  514. /* This is the most reliable way to avoid incompatibilities
  515.    in available built-in functions on various systems.  */
  516. static void
  517. __yy_memcpy (char *to, char *from, int count)
  518. {
  519.   register char *t = to;
  520.   register char *f = from;
  521.   register int i = count;
  522.  
  523.   while (i-- > 0)
  524.     *t++ = *f++;
  525. }
  526.  
  527. #endif
  528. #endif
  529.  
  530. #line 196 "/p/share/bison.simple"
  531.  
  532. /* The user can define YYPARSE_PARAM as the name of an argument to be passed
  533.    into yyparse.  The argument should have type void *.
  534.    It should actually point to an object.
  535.    Grammar actions can access the variable by casting it
  536.    to the proper pointer type.  */
  537.  
  538. #ifdef YYPARSE_PARAM
  539. #ifdef __cplusplus
  540. #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
  541. #define YYPARSE_PARAM_DECL
  542. #else /* not __cplusplus */
  543. #define YYPARSE_PARAM_ARG YYPARSE_PARAM
  544. #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
  545. #endif /* not __cplusplus */
  546. #else /* not YYPARSE_PARAM */
  547. #define YYPARSE_PARAM_ARG
  548. #define YYPARSE_PARAM_DECL
  549. #endif /* not YYPARSE_PARAM */
  550.  
  551. int
  552. yyparse(YYPARSE_PARAM_ARG)
  553.      YYPARSE_PARAM_DECL
  554. {
  555.   register int yystate;
  556.   register int yyn;
  557.   register short *yyssp;
  558.   register YYSTYPE *yyvsp;
  559.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  560.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  561.  
  562.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  563.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  564.  
  565.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  566.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  567.  
  568. #ifdef YYLSP_NEEDED
  569.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  570.   YYLTYPE *yyls = yylsa;
  571.   YYLTYPE *yylsp;
  572.  
  573. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  574. #else
  575. #define YYPOPSTACK   (yyvsp--, yyssp--)
  576. #endif
  577.  
  578.   int yystacksize = YYINITDEPTH;
  579.  
  580. #ifdef YYPURE
  581.   int yychar;
  582.   YYSTYPE yylval;
  583.   int yynerrs;
  584. #ifdef YYLSP_NEEDED
  585.   YYLTYPE yylloc;
  586. #endif
  587. #endif
  588.  
  589.   YYSTYPE yyval;        /*  the variable used to return        */
  590.                 /*  semantic values from the action    */
  591.                 /*  routines                */
  592.  
  593.   int yylen;
  594.  
  595. #if YYDEBUG != 0
  596.   if (yydebug)
  597.     fprintf(stderr, "Starting parse\n");
  598. #endif
  599.  
  600.   yystate = 0;
  601.   yyerrstatus = 0;
  602.   yynerrs = 0;
  603.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  604.  
  605.   /* Initialize stack pointers.
  606.      Waste one element of value and location stack
  607.      so that they stay on the same level as the state stack.
  608.      The wasted elements are never initialized.  */
  609.  
  610.   yyssp = yyss - 1;
  611.   yyvsp = yyvs;
  612. #ifdef YYLSP_NEEDED
  613.   yylsp = yyls;
  614. #endif
  615.  
  616. /* Push a new state, which is found in  yystate  .  */
  617. /* In all cases, when you get here, the value and location stacks
  618.    have just been pushed. so pushing a state here evens the stacks.  */
  619. yynewstate:
  620.  
  621.   *++yyssp = yystate;
  622.  
  623.   if (yyssp >= yyss + yystacksize - 1)
  624.     {
  625.       /* Give user a chance to reallocate the stack */
  626.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  627.       YYSTYPE *yyvs1 = yyvs;
  628.       short *yyss1 = yyss;
  629. #ifdef YYLSP_NEEDED
  630.       YYLTYPE *yyls1 = yyls;
  631. #endif
  632.  
  633.       /* Get the current used size of the three stacks, in elements.  */
  634.       int size = yyssp - yyss + 1;
  635.  
  636. #ifdef yyoverflow
  637.       /* Each stack pointer address is followed by the size of
  638.      the data in use in that stack, in bytes.  */
  639. #ifdef YYLSP_NEEDED
  640.       /* This used to be a conditional around just the two extra args,
  641.      but that might be undefined if yyoverflow is a macro.  */
  642.       yyoverflow("parser stack overflow",
  643.          &yyss1, size * sizeof (*yyssp),
  644.          &yyvs1, size * sizeof (*yyvsp),
  645.          &yyls1, size * sizeof (*yylsp),
  646.          &yystacksize);
  647. #else
  648.       yyoverflow("parser stack overflow",
  649.          &yyss1, size * sizeof (*yyssp),
  650.          &yyvs1, size * sizeof (*yyvsp),
  651.          &yystacksize);
  652. #endif
  653.  
  654.       yyss = yyss1; yyvs = yyvs1;
  655. #ifdef YYLSP_NEEDED
  656.       yyls = yyls1;
  657. #endif
  658. #else /* no yyoverflow */
  659.       /* Extend the stack our own way.  */
  660.       if (yystacksize >= YYMAXDEPTH)
  661.     {
  662.       yyerror("parser stack overflow");
  663.       return 2;
  664.     }
  665.       yystacksize *= 2;
  666.       if (yystacksize > YYMAXDEPTH)
  667.     yystacksize = YYMAXDEPTH;
  668.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  669.       __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
  670.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  671.       __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
  672. #ifdef YYLSP_NEEDED
  673.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  674.       __yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
  675. #endif
  676. #endif /* no yyoverflow */
  677.  
  678.       yyssp = yyss + size - 1;
  679.       yyvsp = yyvs + size - 1;
  680. #ifdef YYLSP_NEEDED
  681.       yylsp = yyls + size - 1;
  682. #endif
  683.  
  684. #if YYDEBUG != 0
  685.       if (yydebug)
  686.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  687. #endif
  688.  
  689.       if (yyssp >= yyss + yystacksize - 1)
  690.     YYABORT;
  691.     }
  692.  
  693. #if YYDEBUG != 0
  694.   if (yydebug)
  695.     fprintf(stderr, "Entering state %d\n", yystate);
  696. #endif
  697.  
  698.   goto yybackup;
  699.  yybackup:
  700.  
  701. /* Do appropriate processing given the current state.  */
  702. /* Read a lookahead token if we need one and don't already have one.  */
  703. /* yyresume: */
  704.  
  705.   /* First try to decide what to do without reference to lookahead token.  */
  706.  
  707.   yyn = yypact[yystate];
  708.   if (yyn == YYFLAG)
  709.     goto yydefault;
  710.  
  711.   /* Not known => get a lookahead token if don't already have one.  */
  712.  
  713.   /* yychar is either YYEMPTY or YYEOF
  714.      or a valid token in external form.  */
  715.  
  716.   if (yychar == YYEMPTY)
  717.     {
  718. #if YYDEBUG != 0
  719.       if (yydebug)
  720.     fprintf(stderr, "Reading a token: ");
  721. #endif
  722.       yychar = YYLEX;
  723.     }
  724.  
  725.   /* Convert token to internal form (in yychar1) for indexing tables with */
  726.  
  727.   if (yychar <= 0)        /* This means end of input. */
  728.     {
  729.       yychar1 = 0;
  730.       yychar = YYEOF;        /* Don't call YYLEX any more */
  731.  
  732. #if YYDEBUG != 0
  733.       if (yydebug)
  734.     fprintf(stderr, "Now at end of input.\n");
  735. #endif
  736.     }
  737.   else
  738.     {
  739.       yychar1 = YYTRANSLATE(yychar);
  740.  
  741. #if YYDEBUG != 0
  742.       if (yydebug)
  743.     {
  744.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  745.       /* Give the individual parser a way to print the precise meaning
  746.          of a token, for further debugging info.  */
  747. #ifdef YYPRINT
  748.       YYPRINT (stderr, yychar, yylval);
  749. #endif
  750.       fprintf (stderr, ")\n");
  751.     }
  752. #endif
  753.     }
  754.  
  755.   yyn += yychar1;
  756.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  757.     goto yydefault;
  758.  
  759.   yyn = yytable[yyn];
  760.  
  761.   /* yyn is what to do for this token type in this state.
  762.      Negative => reduce, -yyn is rule number.
  763.      Positive => shift, yyn is new state.
  764.        New state is final state => don't bother to shift,
  765.        just return success.
  766.      0, or most negative number => error.  */
  767.  
  768.   if (yyn < 0)
  769.     {
  770.       if (yyn == YYFLAG)
  771.     goto yyerrlab;
  772.       yyn = -yyn;
  773.       goto yyreduce;
  774.     }
  775.   else if (yyn == 0)
  776.     goto yyerrlab;
  777.  
  778.   if (yyn == YYFINAL)
  779.     YYACCEPT;
  780.  
  781.   /* Shift the lookahead token.  */
  782.  
  783. #if YYDEBUG != 0
  784.   if (yydebug)
  785.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  786. #endif
  787.  
  788.   /* Discard the token being shifted unless it is eof.  */
  789.   if (yychar != YYEOF)
  790.     yychar = YYEMPTY;
  791.  
  792.   *++yyvsp = yylval;
  793. #ifdef YYLSP_NEEDED
  794.   *++yylsp = yylloc;
  795. #endif
  796.  
  797.   /* count tokens shifted since error; after three, turn off error status.  */
  798.   if (yyerrstatus) yyerrstatus--;
  799.  
  800.   yystate = yyn;
  801.   goto yynewstate;
  802.  
  803. /* Do the default action for the current state.  */
  804. yydefault:
  805.  
  806.   yyn = yydefact[yystate];
  807.   if (yyn == 0)
  808.     goto yyerrlab;
  809.  
  810. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  811. yyreduce:
  812.   yylen = yyr2[yyn];
  813.   if (yylen > 0)
  814.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  815.  
  816. #if YYDEBUG != 0
  817.   if (yydebug)
  818.     {
  819.       int i;
  820.  
  821.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  822.            yyn, yyrline[yyn]);
  823.  
  824.       /* Print the symbols being reduced, and their result.  */
  825.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  826.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  827.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  828.     }
  829. #endif
  830.  
  831.  
  832.   switch (yyn) {
  833.  
  834. case 3:
  835. #line 174 "./getdate.y"
  836. {
  837.         yyHaveTime++;
  838.     ;
  839.     break;}
  840. case 4:
  841. #line 177 "./getdate.y"
  842. {
  843.         yyHaveZone++;
  844.     ;
  845.     break;}
  846. case 5:
  847. #line 180 "./getdate.y"
  848. {
  849.         yyHaveDate++;
  850.     ;
  851.     break;}
  852. case 6:
  853. #line 183 "./getdate.y"
  854. {
  855.         yyHaveDay++;
  856.     ;
  857.     break;}
  858. case 7:
  859. #line 186 "./getdate.y"
  860. {
  861.         yyHaveRel++;
  862.     ;
  863.     break;}
  864. case 9:
  865. #line 192 "./getdate.y"
  866. {
  867.         yyHour = yyvsp[-1].Number;
  868.         yyMinutes = 0;
  869.         yySeconds = 0;
  870.         yyMeridian = yyvsp[0].Meridian;
  871.     ;
  872.     break;}
  873. case 10:
  874. #line 198 "./getdate.y"
  875. {
  876.         yyHour = yyvsp[-3].Number;
  877.         yyMinutes = yyvsp[-1].Number;
  878.         yySeconds = 0;
  879.         yyMeridian = yyvsp[0].Meridian;
  880.     ;
  881.     break;}
  882. case 11:
  883. #line 204 "./getdate.y"
  884. {
  885.         yyHour = yyvsp[-3].Number;
  886.         yyMinutes = yyvsp[-1].Number;
  887.         yyMeridian = MER24;
  888.         yyDSTmode = DSToff;
  889.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  890.     ;
  891.     break;}
  892. case 12:
  893. #line 211 "./getdate.y"
  894. {
  895.         yyHour = yyvsp[-5].Number;
  896.         yyMinutes = yyvsp[-3].Number;
  897.         yySeconds = yyvsp[-1].Number;
  898.         yyMeridian = yyvsp[0].Meridian;
  899.     ;
  900.     break;}
  901. case 13:
  902. #line 217 "./getdate.y"
  903. {
  904.         yyHour = yyvsp[-5].Number;
  905.         yyMinutes = yyvsp[-3].Number;
  906.         yySeconds = yyvsp[-1].Number;
  907.         yyMeridian = MER24;
  908.         yyDSTmode = DSToff;
  909.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  910.     ;
  911.     break;}
  912. case 14:
  913. #line 227 "./getdate.y"
  914. {
  915.         yyTimezone = yyvsp[0].Number;
  916.         yyDSTmode = DSToff;
  917.     ;
  918.     break;}
  919. case 15:
  920. #line 231 "./getdate.y"
  921. {
  922.         yyTimezone = yyvsp[0].Number;
  923.         yyDSTmode = DSTon;
  924.     ;
  925.     break;}
  926. case 16:
  927. #line 236 "./getdate.y"
  928. {
  929.         yyTimezone = yyvsp[-1].Number;
  930.         yyDSTmode = DSTon;
  931.     ;
  932.     break;}
  933. case 17:
  934. #line 242 "./getdate.y"
  935. {
  936.         yyDayOrdinal = 1;
  937.         yyDayNumber = yyvsp[0].Number;
  938.     ;
  939.     break;}
  940. case 18:
  941. #line 246 "./getdate.y"
  942. {
  943.         yyDayOrdinal = 1;
  944.         yyDayNumber = yyvsp[-1].Number;
  945.     ;
  946.     break;}
  947. case 19:
  948. #line 250 "./getdate.y"
  949. {
  950.         yyDayOrdinal = yyvsp[-1].Number;
  951.         yyDayNumber = yyvsp[0].Number;
  952.     ;
  953.     break;}
  954. case 20:
  955. #line 256 "./getdate.y"
  956. {
  957.         yyMonth = yyvsp[-2].Number;
  958.         yyDay = yyvsp[0].Number;
  959.     ;
  960.     break;}
  961. case 21:
  962. #line 260 "./getdate.y"
  963. {
  964.         yyMonth = yyvsp[-4].Number;
  965.         yyDay = yyvsp[-2].Number;
  966.         yyYear = yyvsp[0].Number;
  967.     ;
  968.     break;}
  969. case 22:
  970. #line 265 "./getdate.y"
  971. {
  972.         /* ISO 8601 format.  yyyy-mm-dd.  */
  973.         yyYear = yyvsp[-2].Number;
  974.         yyMonth = -yyvsp[-1].Number;
  975.         yyDay = -yyvsp[0].Number;
  976.     ;
  977.     break;}
  978. case 23:
  979. #line 271 "./getdate.y"
  980. {
  981.         /* e.g. 17-JUN-1992.  */
  982.         yyDay = yyvsp[-2].Number;
  983.         yyMonth = yyvsp[-1].Number;
  984.         yyYear = -yyvsp[0].Number;
  985.     ;
  986.     break;}
  987. case 24:
  988. #line 277 "./getdate.y"
  989. {
  990.         yyMonth = yyvsp[-1].Number;
  991.         yyDay = yyvsp[0].Number;
  992.     ;
  993.     break;}
  994. case 25:
  995. #line 281 "./getdate.y"
  996. {
  997.         yyMonth = yyvsp[-3].Number;
  998.         yyDay = yyvsp[-2].Number;
  999.         yyYear = yyvsp[0].Number;
  1000.     ;
  1001.     break;}
  1002. case 26:
  1003. #line 286 "./getdate.y"
  1004. {
  1005.         yyMonth = yyvsp[0].Number;
  1006.         yyDay = yyvsp[-1].Number;
  1007.     ;
  1008.     break;}
  1009. case 27:
  1010. #line 290 "./getdate.y"
  1011. {
  1012.         yyMonth = yyvsp[-1].Number;
  1013.         yyDay = yyvsp[-2].Number;
  1014.         yyYear = yyvsp[0].Number;
  1015.     ;
  1016.     break;}
  1017. case 28:
  1018. #line 297 "./getdate.y"
  1019. {
  1020.         yyRelSeconds = -yyRelSeconds;
  1021.         yyRelMonth = -yyRelMonth;
  1022.     ;
  1023.     break;}
  1024. case 30:
  1025. #line 304 "./getdate.y"
  1026. {
  1027.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1028.     ;
  1029.     break;}
  1030. case 31:
  1031. #line 307 "./getdate.y"
  1032. {
  1033.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1034.     ;
  1035.     break;}
  1036. case 32:
  1037. #line 310 "./getdate.y"
  1038. {
  1039.         yyRelSeconds += yyvsp[0].Number * 60L;
  1040.     ;
  1041.     break;}
  1042. case 33:
  1043. #line 313 "./getdate.y"
  1044. {
  1045.         yyRelSeconds += yyvsp[-1].Number;
  1046.     ;
  1047.     break;}
  1048. case 34:
  1049. #line 316 "./getdate.y"
  1050. {
  1051.         yyRelSeconds += yyvsp[-1].Number;
  1052.     ;
  1053.     break;}
  1054. case 35:
  1055. #line 319 "./getdate.y"
  1056. {
  1057.         yyRelSeconds++;
  1058.     ;
  1059.     break;}
  1060. case 36:
  1061. #line 322 "./getdate.y"
  1062. {
  1063.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1064.     ;
  1065.     break;}
  1066. case 37:
  1067. #line 325 "./getdate.y"
  1068. {
  1069.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1070.     ;
  1071.     break;}
  1072. case 38:
  1073. #line 328 "./getdate.y"
  1074. {
  1075.         yyRelMonth += yyvsp[0].Number;
  1076.     ;
  1077.     break;}
  1078. case 39:
  1079. #line 333 "./getdate.y"
  1080. {
  1081.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1082.         yyYear = yyvsp[0].Number;
  1083.         else {
  1084.         if (yyvsp[0].Number>10000) {
  1085.             yyHaveDate++;
  1086.             yyDay= (yyvsp[0].Number)%100;
  1087.             yyMonth= (yyvsp[0].Number/100)%100;
  1088.             yyYear = yyvsp[0].Number/10000;
  1089.         }
  1090.         else {
  1091.             yyHaveTime++;
  1092.             if (yyvsp[0].Number < 100) {
  1093.             yyHour = yyvsp[0].Number;
  1094.             yyMinutes = 0;
  1095.             }
  1096.             else {
  1097.                 yyHour = yyvsp[0].Number / 100;
  1098.                 yyMinutes = yyvsp[0].Number % 100;
  1099.             }
  1100.             yySeconds = 0;
  1101.             yyMeridian = MER24;
  1102.             }
  1103.         }
  1104.     ;
  1105.     break;}
  1106. case 40:
  1107. #line 360 "./getdate.y"
  1108. {
  1109.         yyval.Meridian = MER24;
  1110.     ;
  1111.     break;}
  1112. case 41:
  1113. #line 363 "./getdate.y"
  1114. {
  1115.         yyval.Meridian = yyvsp[0].Meridian;
  1116.     ;
  1117.     break;}
  1118. }
  1119.    /* the action file gets copied in in place of this dollarsign */
  1120. #line 498 "/p/share/bison.simple"
  1121.  
  1122.   yyvsp -= yylen;
  1123.   yyssp -= yylen;
  1124. #ifdef YYLSP_NEEDED
  1125.   yylsp -= yylen;
  1126. #endif
  1127.  
  1128. #if YYDEBUG != 0
  1129.   if (yydebug)
  1130.     {
  1131.       short *ssp1 = yyss - 1;
  1132.       fprintf (stderr, "state stack now");
  1133.       while (ssp1 != yyssp)
  1134.     fprintf (stderr, " %d", *++ssp1);
  1135.       fprintf (stderr, "\n");
  1136.     }
  1137. #endif
  1138.  
  1139.   *++yyvsp = yyval;
  1140.  
  1141. #ifdef YYLSP_NEEDED
  1142.   yylsp++;
  1143.   if (yylen == 0)
  1144.     {
  1145.       yylsp->first_line = yylloc.first_line;
  1146.       yylsp->first_column = yylloc.first_column;
  1147.       yylsp->last_line = (yylsp-1)->last_line;
  1148.       yylsp->last_column = (yylsp-1)->last_column;
  1149.       yylsp->text = 0;
  1150.     }
  1151.   else
  1152.     {
  1153.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1154.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1155.     }
  1156. #endif
  1157.  
  1158.   /* Now "shift" the result of the reduction.
  1159.      Determine what state that goes to,
  1160.      based on the state we popped back to
  1161.      and the rule number reduced by.  */
  1162.  
  1163.   yyn = yyr1[yyn];
  1164.  
  1165.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1166.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1167.     yystate = yytable[yystate];
  1168.   else
  1169.     yystate = yydefgoto[yyn - YYNTBASE];
  1170.  
  1171.   goto yynewstate;
  1172.  
  1173. yyerrlab:   /* here on detecting error */
  1174.  
  1175.   if (! yyerrstatus)
  1176.     /* If not already recovering from an error, report this error.  */
  1177.     {
  1178.       ++yynerrs;
  1179.  
  1180. #ifdef YYERROR_VERBOSE
  1181.       yyn = yypact[yystate];
  1182.  
  1183.       if (yyn > YYFLAG && yyn < YYLAST)
  1184.     {
  1185.       int size = 0;
  1186.       char *msg;
  1187.       int x, count;
  1188.  
  1189.       count = 0;
  1190.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1191.       for (x = (yyn < 0 ? -yyn : 0);
  1192.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1193.         if (yycheck[x + yyn] == x)
  1194.           size += strlen(yytname[x]) + 15, count++;
  1195.       msg = (char *) malloc(size + 15);
  1196.       if (msg != 0)
  1197.         {
  1198.           strcpy(msg, "parse error");
  1199.  
  1200.           if (count < 5)
  1201.         {
  1202.           count = 0;
  1203.           for (x = (yyn < 0 ? -yyn : 0);
  1204.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1205.             if (yycheck[x + yyn] == x)
  1206.               {
  1207.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1208.             strcat(msg, yytname[x]);
  1209.             strcat(msg, "'");
  1210.             count++;
  1211.               }
  1212.         }
  1213.           yyerror(msg);
  1214.           free(msg);
  1215.         }
  1216.       else
  1217.         yyerror ("parse error; also virtual memory exceeded");
  1218.     }
  1219.       else
  1220. #endif /* YYERROR_VERBOSE */
  1221.     yyerror("parse error");
  1222.     }
  1223.  
  1224.   goto yyerrlab1;
  1225. yyerrlab1:   /* here on error raised explicitly by an action */
  1226.  
  1227.   if (yyerrstatus == 3)
  1228.     {
  1229.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1230.  
  1231.       /* return failure if at end of input */
  1232.       if (yychar == YYEOF)
  1233.     YYABORT;
  1234.  
  1235. #if YYDEBUG != 0
  1236.       if (yydebug)
  1237.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1238. #endif
  1239.  
  1240.       yychar = YYEMPTY;
  1241.     }
  1242.  
  1243.   /* Else will try to reuse lookahead token
  1244.      after shifting the error token.  */
  1245.  
  1246.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1247.  
  1248.   goto yyerrhandle;
  1249.  
  1250. yyerrdefault:  /* current state does not do anything special for the error token. */
  1251.  
  1252. #if 0
  1253.   /* This is wrong; only states that explicitly want error tokens
  1254.      should shift them.  */
  1255.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1256.   if (yyn) goto yydefault;
  1257. #endif
  1258.  
  1259. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1260.  
  1261.   if (yyssp == yyss) YYABORT;
  1262.   yyvsp--;
  1263.   yystate = *--yyssp;
  1264. #ifdef YYLSP_NEEDED
  1265.   yylsp--;
  1266. #endif
  1267.  
  1268. #if YYDEBUG != 0
  1269.   if (yydebug)
  1270.     {
  1271.       short *ssp1 = yyss - 1;
  1272.       fprintf (stderr, "Error: state stack now");
  1273.       while (ssp1 != yyssp)
  1274.     fprintf (stderr, " %d", *++ssp1);
  1275.       fprintf (stderr, "\n");
  1276.     }
  1277. #endif
  1278.  
  1279. yyerrhandle:
  1280.  
  1281.   yyn = yypact[yystate];
  1282.   if (yyn == YYFLAG)
  1283.     goto yyerrdefault;
  1284.  
  1285.   yyn += YYTERROR;
  1286.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1287.     goto yyerrdefault;
  1288.  
  1289.   yyn = yytable[yyn];
  1290.   if (yyn < 0)
  1291.     {
  1292.       if (yyn == YYFLAG)
  1293.     goto yyerrpop;
  1294.       yyn = -yyn;
  1295.       goto yyreduce;
  1296.     }
  1297.   else if (yyn == 0)
  1298.     goto yyerrpop;
  1299.  
  1300.   if (yyn == YYFINAL)
  1301.     YYACCEPT;
  1302.  
  1303. #if YYDEBUG != 0
  1304.   if (yydebug)
  1305.     fprintf(stderr, "Shifting error token, ");
  1306. #endif
  1307.  
  1308.   *++yyvsp = yylval;
  1309. #ifdef YYLSP_NEEDED
  1310.   *++yylsp = yylloc;
  1311. #endif
  1312.  
  1313.   yystate = yyn;
  1314.   goto yynewstate;
  1315. }
  1316. #line 368 "./getdate.y"
  1317.  
  1318.  
  1319. /* Month and day table. */
  1320. static TABLE const MonthDayTable[] = {
  1321.     { "january",    tMONTH,  1 },
  1322.     { "february",    tMONTH,  2 },
  1323.     { "march",        tMONTH,  3 },
  1324.     { "april",        tMONTH,  4 },
  1325.     { "may",        tMONTH,  5 },
  1326.     { "june",        tMONTH,  6 },
  1327.     { "july",        tMONTH,  7 },
  1328.     { "august",        tMONTH,  8 },
  1329.     { "september",    tMONTH,  9 },
  1330.     { "sept",        tMONTH,  9 },
  1331.     { "october",    tMONTH, 10 },
  1332.     { "november",    tMONTH, 11 },
  1333.     { "december",    tMONTH, 12 },
  1334.     { "sunday",        tDAY, 0 },
  1335.     { "monday",        tDAY, 1 },
  1336.     { "tuesday",    tDAY, 2 },
  1337.     { "tues",        tDAY, 2 },
  1338.     { "wednesday",    tDAY, 3 },
  1339.     { "wednes",        tDAY, 3 },
  1340.     { "thursday",    tDAY, 4 },
  1341.     { "thur",        tDAY, 4 },
  1342.     { "thurs",        tDAY, 4 },
  1343.     { "friday",        tDAY, 5 },
  1344.     { "saturday",    tDAY, 6 },
  1345.     { NULL }
  1346. };
  1347.  
  1348. /* Time units table. */
  1349. static TABLE const UnitsTable[] = {
  1350.     { "year",        tMONTH_UNIT,    12 },
  1351.     { "month",        tMONTH_UNIT,    1 },
  1352.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1353.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1354.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1355.     { "hour",        tMINUTE_UNIT,    60 },
  1356.     { "minute",        tMINUTE_UNIT,    1 },
  1357.     { "min",        tMINUTE_UNIT,    1 },
  1358.     { "second",        tSEC_UNIT,    1 },
  1359.     { "sec",        tSEC_UNIT,    1 },
  1360.     { NULL }
  1361. };
  1362.  
  1363. /* Assorted relative-time words. */
  1364. static TABLE const OtherTable[] = {
  1365.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1366.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1367.     { "today",        tMINUTE_UNIT,    0 },
  1368.     { "now",        tMINUTE_UNIT,    0 },
  1369.     { "last",        tUNUMBER,    -1 },
  1370.     { "this",        tMINUTE_UNIT,    0 },
  1371.     { "next",        tUNUMBER,    2 },
  1372.     { "first",        tUNUMBER,    1 },
  1373. /*  { "second",        tUNUMBER,    2 }, */
  1374.     { "third",        tUNUMBER,    3 },
  1375.     { "fourth",        tUNUMBER,    4 },
  1376.     { "fifth",        tUNUMBER,    5 },
  1377.     { "sixth",        tUNUMBER,    6 },
  1378.     { "seventh",    tUNUMBER,    7 },
  1379.     { "eighth",        tUNUMBER,    8 },
  1380.     { "ninth",        tUNUMBER,    9 },
  1381.     { "tenth",        tUNUMBER,    10 },
  1382.     { "eleventh",    tUNUMBER,    11 },
  1383.     { "twelfth",    tUNUMBER,    12 },
  1384.     { "ago",        tAGO,    1 },
  1385.     { NULL }
  1386. };
  1387.  
  1388. /* The timezone table. */
  1389. /* Some of these are commented out because a time_t can't store a float. */
  1390. static TABLE const TimezoneTable[] = {
  1391.     { "gmt",    tZONE,     HOUR ( 0) },    /* Greenwich Mean */
  1392.     { "ut",    tZONE,     HOUR ( 0) },    /* Universal (Coordinated) */
  1393.     { "utc",    tZONE,     HOUR ( 0) },
  1394.     { "wet",    tZONE,     HOUR ( 0) },    /* Western European */
  1395.     { "bst",    tDAYZONE,  HOUR ( 0) },    /* British Summer */
  1396.     { "wat",    tZONE,     HOUR ( 1) },    /* West Africa */
  1397.     { "at",    tZONE,     HOUR ( 2) },    /* Azores */
  1398. #if    0
  1399.     /* For completeness.  BST is also British Summer, and GST is
  1400.      * also Guam Standard. */
  1401.     { "bst",    tZONE,     HOUR ( 3) },    /* Brazil Standard */
  1402.     { "gst",    tZONE,     HOUR ( 3) },    /* Greenland Standard */
  1403. #endif
  1404. #if 0
  1405.     { "nft",    tZONE,     HOUR (3.5) },    /* Newfoundland */
  1406.     { "nst",    tZONE,     HOUR (3.5) },    /* Newfoundland Standard */
  1407.     { "ndt",    tDAYZONE,  HOUR (3.5) },    /* Newfoundland Daylight */
  1408. #endif
  1409.     { "ast",    tZONE,     HOUR ( 4) },    /* Atlantic Standard */
  1410.     { "adt",    tDAYZONE,  HOUR ( 4) },    /* Atlantic Daylight */
  1411.     { "est",    tZONE,     HOUR ( 5) },    /* Eastern Standard */
  1412.     { "edt",    tDAYZONE,  HOUR ( 5) },    /* Eastern Daylight */
  1413.     { "cst",    tZONE,     HOUR ( 6) },    /* Central Standard */
  1414.     { "cdt",    tDAYZONE,  HOUR ( 6) },    /* Central Daylight */
  1415.     { "mst",    tZONE,     HOUR ( 7) },    /* Mountain Standard */
  1416.     { "mdt",    tDAYZONE,  HOUR ( 7) },    /* Mountain Daylight */
  1417.     { "pst",    tZONE,     HOUR ( 8) },    /* Pacific Standard */
  1418.     { "pdt",    tDAYZONE,  HOUR ( 8) },    /* Pacific Daylight */
  1419.     { "yst",    tZONE,     HOUR ( 9) },    /* Yukon Standard */
  1420.     { "ydt",    tDAYZONE,  HOUR ( 9) },    /* Yukon Daylight */
  1421.     { "hst",    tZONE,     HOUR (10) },    /* Hawaii Standard */
  1422.     { "hdt",    tDAYZONE,  HOUR (10) },    /* Hawaii Daylight */
  1423.     { "cat",    tZONE,     HOUR (10) },    /* Central Alaska */
  1424.     { "ahst",    tZONE,     HOUR (10) },    /* Alaska-Hawaii Standard */
  1425.     { "nt",    tZONE,     HOUR (11) },    /* Nome */
  1426.     { "idlw",    tZONE,     HOUR (12) },    /* International Date Line West */
  1427.     { "cet",    tZONE,     -HOUR (1) },    /* Central European */
  1428.     { "met",    tZONE,     -HOUR (1) },    /* Middle European */
  1429.     { "mewt",    tZONE,     -HOUR (1) },    /* Middle European Winter */
  1430.     { "mest",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1431.     { "mesz",    tDAYZONE,  -HOUR (1) },    /* Middle European Summer */
  1432.     { "swt",    tZONE,     -HOUR (1) },    /* Swedish Winter */
  1433.     { "sst",    tDAYZONE,  -HOUR (1) },    /* Swedish Summer */
  1434.     { "fwt",    tZONE,     -HOUR (1) },    /* French Winter */
  1435.     { "fst",    tDAYZONE,  -HOUR (1) },    /* French Summer */
  1436.     { "eet",    tZONE,     -HOUR (2) },    /* Eastern Europe, USSR Zone 1 */
  1437.     { "bt",    tZONE,     -HOUR (3) },    /* Baghdad, USSR Zone 2 */
  1438. #if 0
  1439.     { "it",    tZONE,     -HOUR (3.5) },/* Iran */
  1440. #endif
  1441.     { "zp4",    tZONE,     -HOUR (4) },    /* USSR Zone 3 */
  1442.     { "zp5",    tZONE,     -HOUR (5) },    /* USSR Zone 4 */
  1443. #if 0
  1444.     { "ist",    tZONE,     -HOUR (5.5) },/* Indian Standard */
  1445. #endif
  1446.     { "zp6",    tZONE,     -HOUR (6) },    /* USSR Zone 5 */
  1447. #if    0
  1448.     /* For completeness.  NST is also Newfoundland Standard, and SST is
  1449.      * also Swedish Summer. */
  1450.     { "nst",    tZONE,     -HOUR (6.5) },/* North Sumatra */
  1451.     { "sst",    tZONE,     -HOUR (7) },    /* South Sumatra, USSR Zone 6 */
  1452. #endif    /* 0 */
  1453.     { "wast",    tZONE,     -HOUR (7) },    /* West Australian Standard */
  1454.     { "wadt",    tDAYZONE,  -HOUR (7) },    /* West Australian Daylight */
  1455. #if 0
  1456.     { "jt",    tZONE,     -HOUR (7.5) },/* Java (3pm in Cronusland!) */
  1457. #endif
  1458.     { "cct",    tZONE,     -HOUR (8) },    /* China Coast, USSR Zone 7 */
  1459.     { "jst",    tZONE,     -HOUR (9) },    /* Japan Standard, USSR Zone 8 */
  1460. #if 0
  1461.     { "cast",    tZONE,     -HOUR (9.5) },/* Central Australian Standard */
  1462.     { "cadt",    tDAYZONE,  -HOUR (9.5) },/* Central Australian Daylight */
  1463. #endif
  1464.     { "east",    tZONE,     -HOUR (10) },    /* Eastern Australian Standard */
  1465.     { "eadt",    tDAYZONE,  -HOUR (10) },    /* Eastern Australian Daylight */
  1466.     { "gst",    tZONE,     -HOUR (10) },    /* Guam Standard, USSR Zone 9 */
  1467.     { "nzt",    tZONE,     -HOUR (12) },    /* New Zealand */
  1468.     { "nzst",    tZONE,     -HOUR (12) },    /* New Zealand Standard */
  1469.     { "nzdt",    tDAYZONE,  -HOUR (12) },    /* New Zealand Daylight */
  1470.     { "idle",    tZONE,     -HOUR (12) },    /* International Date Line East */
  1471.     {  NULL  }
  1472. };
  1473.  
  1474. /* Military timezone table. */
  1475. static TABLE const MilitaryTable[] = {
  1476.     { "a",    tZONE,    HOUR (  1) },
  1477.     { "b",    tZONE,    HOUR (  2) },
  1478.     { "c",    tZONE,    HOUR (  3) },
  1479.     { "d",    tZONE,    HOUR (  4) },
  1480.     { "e",    tZONE,    HOUR (  5) },
  1481.     { "f",    tZONE,    HOUR (  6) },
  1482.     { "g",    tZONE,    HOUR (  7) },
  1483.     { "h",    tZONE,    HOUR (  8) },
  1484.     { "i",    tZONE,    HOUR (  9) },
  1485.     { "k",    tZONE,    HOUR ( 10) },
  1486.     { "l",    tZONE,    HOUR ( 11) },
  1487.     { "m",    tZONE,    HOUR ( 12) },
  1488.     { "n",    tZONE,    HOUR (- 1) },
  1489.     { "o",    tZONE,    HOUR (- 2) },
  1490.     { "p",    tZONE,    HOUR (- 3) },
  1491.     { "q",    tZONE,    HOUR (- 4) },
  1492.     { "r",    tZONE,    HOUR (- 5) },
  1493.     { "s",    tZONE,    HOUR (- 6) },
  1494.     { "t",    tZONE,    HOUR (- 7) },
  1495.     { "u",    tZONE,    HOUR (- 8) },
  1496.     { "v",    tZONE,    HOUR (- 9) },
  1497.     { "w",    tZONE,    HOUR (-10) },
  1498.     { "x",    tZONE,    HOUR (-11) },
  1499.     { "y",    tZONE,    HOUR (-12) },
  1500.     { "z",    tZONE,    HOUR (  0) },
  1501.     { NULL }
  1502. };
  1503.  
  1504.  
  1505.  
  1506.  
  1507. /* ARGSUSED */
  1508. static int
  1509. yyerror (s)
  1510.     char    *s;
  1511. {
  1512.   return 0;
  1513. }
  1514.  
  1515.  
  1516. static time_t
  1517. ToSeconds (Hours, Minutes, Seconds, Meridian)
  1518.     time_t    Hours;
  1519.     time_t    Minutes;
  1520.     time_t    Seconds;
  1521.     MERIDIAN    Meridian;
  1522. {
  1523.   if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1524.     return -1;
  1525.   switch (Meridian) {
  1526.   case MER24:
  1527.     if (Hours < 0 || Hours > 23)
  1528.       return -1;
  1529.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1530.   case MERam:
  1531.     if (Hours < 1 || Hours > 12)
  1532.       return -1;
  1533.     if (Hours == 12)
  1534.       Hours = 0;
  1535.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1536.   case MERpm:
  1537.     if (Hours < 1 || Hours > 12)
  1538.       return -1;
  1539.     if (Hours == 12)
  1540.       Hours = 0;
  1541.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1542.   default:
  1543.     abort ();
  1544.   }
  1545.   /* NOTREACHED */
  1546. }
  1547.  
  1548.  
  1549. static time_t
  1550. Convert (Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1551.     time_t    Month;
  1552.     time_t    Day;
  1553.     time_t    Year;
  1554.     time_t    Hours;
  1555.     time_t    Minutes;
  1556.     time_t    Seconds;
  1557.     MERIDIAN    Meridian;
  1558.     DSTMODE    DSTmode;
  1559. {
  1560.   static int DaysInMonth[12] = {
  1561.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1562.   };
  1563.   time_t    tod;
  1564.   time_t    Julian;
  1565.   int        i;
  1566.  
  1567.   if (Year < 0)
  1568.     Year = -Year;
  1569.   if (Year < DOOMSDAY-2000)
  1570.     Year += 2000;
  1571.   else if (Year < 100)
  1572.     Year += 1900;
  1573.   DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1574.     ? 29 : 28;
  1575.   if (Year < EPOCH || Year >= DOOMSDAY
  1576.       || Month < 1 || Month > 12
  1577.       /* Lint fluff:  "conversion from long may lose accuracy" */
  1578.       || Day < 1 || Day > DaysInMonth[(int)--Month])
  1579.     return -1;
  1580.  
  1581.   for (Julian = Day - 1, i = 0; i < Month; i++)
  1582.     Julian += DaysInMonth[i];
  1583.   for (i = EPOCH; i < Year; i++)
  1584.     Julian += 365 + (i % 4 == 0);
  1585.   Julian *= SECSPERDAY;
  1586.   Julian += yyTimezone * 60L;
  1587.   if ((tod = ToSeconds (Hours, Minutes, Seconds, Meridian)) < 0)
  1588.     return -1;
  1589.   Julian += tod;
  1590.   if (DSTmode == DSTon
  1591.       || (DSTmode == DSTmaybe && localtime (&Julian)->tm_isdst))
  1592.     Julian -= 60 * 60;
  1593.   return Julian;
  1594. }
  1595.  
  1596.  
  1597. static time_t
  1598. DSTcorrect (Start, Future)
  1599.     time_t    Start;
  1600.     time_t    Future;
  1601. {
  1602.   time_t    StartDay;
  1603.   time_t    FutureDay;
  1604.  
  1605.   StartDay = (localtime (&Start)->tm_hour + 1) % 24;
  1606.   FutureDay = (localtime (&Future)->tm_hour + 1) % 24;
  1607.   return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1608. }
  1609.  
  1610.  
  1611. static time_t
  1612. RelativeDate (Start, DayOrdinal, DayNumber)
  1613.     time_t    Start;
  1614.     time_t    DayOrdinal;
  1615.     time_t    DayNumber;
  1616. {
  1617.   struct tm    *tm;
  1618.   time_t    now;
  1619.  
  1620.   now = Start;
  1621.   tm = localtime (&now);
  1622.   now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1623.   now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1624.   return DSTcorrect (Start, now);
  1625. }
  1626.  
  1627.  
  1628. static time_t
  1629. RelativeMonth (Start, RelMonth)
  1630.     time_t    Start;
  1631.     time_t    RelMonth;
  1632. {
  1633.   struct tm    *tm;
  1634.   time_t    Month;
  1635.   time_t    Year;
  1636.  
  1637.   if (RelMonth == 0)
  1638.     return 0;
  1639.   tm = localtime (&Start);
  1640.   Month = 12 * (1900 + tm->tm_year) + tm->tm_mon + RelMonth;
  1641.   Year = Month / 12;
  1642.   Month = Month % 12 + 1;
  1643.   return DSTcorrect (Start,
  1644.              Convert (Month, (time_t)tm->tm_mday, Year,
  1645.                   (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1646.                   MER24, DSTmaybe));
  1647. }
  1648.  
  1649.  
  1650. static int
  1651. LookupWord (buff)
  1652.     char        *buff;
  1653. {
  1654.   register char    *p;
  1655.   register char    *q;
  1656.   register const TABLE    *tp;
  1657.   int            i;
  1658.   int            abbrev;
  1659.  
  1660.   /* Make it lowercase. */
  1661.   for (p = buff; *p; p++)
  1662.     if (isupper (*p))
  1663.       *p = tolower (*p);
  1664.  
  1665.   if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0) {
  1666.     yylval.Meridian = MERam;
  1667.     return tMERIDIAN;
  1668.   }
  1669.   if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0) {
  1670.     yylval.Meridian = MERpm;
  1671.     return tMERIDIAN;
  1672.   }
  1673.  
  1674.   /* See if we have an abbreviation for a month. */
  1675.   if (strlen (buff) == 3)
  1676.     abbrev = 1;
  1677.   else if (strlen (buff) == 4 && buff[3] == '.') {
  1678.     abbrev = 1;
  1679.     buff[3] = '\0';
  1680.   }
  1681.   else
  1682.     abbrev = 0;
  1683.  
  1684.   for (tp = MonthDayTable; tp->name; tp++) {
  1685.     if (abbrev) {
  1686.       if (strncmp (buff, tp->name, 3) == 0) {
  1687.     yylval.Number = tp->value;
  1688.     return tp->type;
  1689.       }
  1690.     }
  1691.     else if (strcmp (buff, tp->name) == 0) {
  1692.       yylval.Number = tp->value;
  1693.       return tp->type;
  1694.     }
  1695.   }
  1696.  
  1697.   for (tp = TimezoneTable; tp->name; tp++)
  1698.     if (strcmp (buff, tp->name) == 0) {
  1699.       yylval.Number = tp->value;
  1700.       return tp->type;
  1701.     }
  1702.  
  1703.   if (strcmp (buff, "dst") == 0)
  1704.     return tDST;
  1705.  
  1706.   for (tp = UnitsTable; tp->name; tp++)
  1707.     if (strcmp (buff, tp->name) == 0) {
  1708.       yylval.Number = tp->value;
  1709.       return tp->type;
  1710.     }
  1711.  
  1712.   /* Strip off any plural and try the units table again. */
  1713.   i = strlen (buff) - 1;
  1714.   if (buff[i] == 's') {
  1715.     buff[i] = '\0';
  1716.     for (tp = UnitsTable; tp->name; tp++)
  1717.       if (strcmp (buff, tp->name) == 0) {
  1718.     yylval.Number = tp->value;
  1719.     return tp->type;
  1720.       }
  1721.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1722.   }
  1723.  
  1724.   for (tp = OtherTable; tp->name; tp++)
  1725.     if (strcmp (buff, tp->name) == 0) {
  1726.       yylval.Number = tp->value;
  1727.       return tp->type;
  1728.     }
  1729.  
  1730.   /* Military timezones. */
  1731.   if (buff[1] == '\0' && isalpha (*buff)) {
  1732.     for (tp = MilitaryTable; tp->name; tp++)
  1733.       if (strcmp (buff, tp->name) == 0) {
  1734.     yylval.Number = tp->value;
  1735.     return tp->type;
  1736.       }
  1737.   }
  1738.  
  1739.   /* Drop out any periods and try the timezone table again. */
  1740.   for (i = 0, p = q = buff; *q; q++)
  1741.     if (*q != '.')
  1742.       *p++ = *q;
  1743.     else
  1744.       i++;
  1745.   *p = '\0';
  1746.   if (i)
  1747.     for (tp = TimezoneTable; tp->name; tp++)
  1748.       if (strcmp (buff, tp->name) == 0) {
  1749.     yylval.Number = tp->value;
  1750.     return tp->type;
  1751.       }
  1752.  
  1753.   return tID;
  1754. }
  1755.  
  1756.  
  1757. static int
  1758. yylex ()
  1759. {
  1760.   register char    c;
  1761.   register char    *p;
  1762.   char        buff[20];
  1763.   int            Count;
  1764.   int            sign;
  1765.  
  1766.   for ( ; ; ) {
  1767.     while (isspace (*yyInput))
  1768.       yyInput++;
  1769.  
  1770.     if (isdigit (c = *yyInput) || c == '-' || c == '+') {
  1771.       if (c == '-' || c == '+') {
  1772.     sign = c == '-' ? -1 : 1;
  1773.     if (!isdigit (*++yyInput))
  1774.       /* skip the '-' sign */
  1775.       continue;
  1776.       }
  1777.       else
  1778.     sign = 0;
  1779.       for (yylval.Number = 0; isdigit (c = *yyInput++); )
  1780.     yylval.Number = 10 * yylval.Number + c - '0';
  1781.       yyInput--;
  1782.       if (sign < 0)
  1783.     yylval.Number = -yylval.Number;
  1784.       return sign ? tSNUMBER : tUNUMBER;
  1785.     }
  1786.     if (isalpha (c)) {
  1787.       for (p = buff; isalpha (c = *yyInput++) || c == '.'; )
  1788.     if (p < &buff[sizeof buff - 1])
  1789.       *p++ = c;
  1790.       *p = '\0';
  1791.       yyInput--;
  1792.       return LookupWord (buff);
  1793.     }
  1794.     if (c != '(')
  1795.       return *yyInput++;
  1796.     Count = 0;
  1797.     do {
  1798.       c = *yyInput++;
  1799.       if (c == '\0')
  1800.     return c;
  1801.       if (c == '(')
  1802.     Count++;
  1803.       else if (c == ')')
  1804.     Count--;
  1805.     } while (Count > 0);
  1806.   }
  1807. }
  1808.  
  1809. #define TM_YEAR_ORIGIN 1900
  1810.  
  1811. /* Yield A - B, measured in seconds.  */
  1812. static long
  1813. difftm (a, b)
  1814.      struct tm *a, *b;
  1815. {
  1816.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  1817.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  1818.   long days = (
  1819.            /* difference in day of year */
  1820.            a->tm_yday - b->tm_yday
  1821.            /* + intervening leap days */
  1822.            +  ((ay >> 2) - (by >> 2))
  1823.            -  (ay/100 - by/100)
  1824.            +  ((ay/100 >> 2) - (by/100 >> 2))
  1825.            /* + difference in years * 365 */
  1826.            +  (long)(ay-by) * 365
  1827.            );
  1828.   return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
  1829.           + (a->tm_min - b->tm_min))
  1830.       + (a->tm_sec - b->tm_sec));
  1831. }
  1832.  
  1833. time_t
  1834. get_date (p, now)
  1835.     char        *p;
  1836.     struct timeb    *now;
  1837. {
  1838.   struct tm        *tm, gmt;
  1839.   struct timeb    ftz;
  1840.   time_t        Start;
  1841.   time_t        tod;
  1842.  
  1843.   yyInput = p;
  1844.   if (now == NULL) {
  1845.     now = &ftz;
  1846.     (void)time (&ftz.time);
  1847.  
  1848.     if (! (tm = gmtime (&ftz.time)))
  1849.       return -1;
  1850.     gmt = *tm;            /* Make a copy, in case localtime modifies *tm.  */
  1851.  
  1852.     if (! (tm = localtime (&ftz.time)))
  1853.       return -1;
  1854.  
  1855.     ftz.timezone = difftm (&gmt, tm) / 60;
  1856.     if (tm->tm_isdst)
  1857.       ftz.timezone += 60;
  1858.   }
  1859.  
  1860.   tm = localtime (&now->time);
  1861.   yyYear = tm->tm_year;
  1862.   yyMonth = tm->tm_mon + 1;
  1863.   yyDay = tm->tm_mday;
  1864.   yyTimezone = now->timezone;
  1865.   yyDSTmode = DSTmaybe;
  1866.   yyHour = 0;
  1867.   yyMinutes = 0;
  1868.   yySeconds = 0;
  1869.   yyMeridian = MER24;
  1870.   yyRelSeconds = 0;
  1871.   yyRelMonth = 0;
  1872.   yyHaveDate = 0;
  1873.   yyHaveDay = 0;
  1874.   yyHaveRel = 0;
  1875.   yyHaveTime = 0;
  1876.   yyHaveZone = 0;
  1877.  
  1878.   if (yyparse ()
  1879.       || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1880.     return -1;
  1881.  
  1882.   if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1883.     Start = Convert (yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1884.              yyMeridian, yyDSTmode);
  1885.     if (Start < 0)
  1886.       return -1;
  1887.   }
  1888.   else {
  1889.     Start = now->time;
  1890.     if (!yyHaveRel)
  1891.       Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1892.   }
  1893.  
  1894.   Start += yyRelSeconds;
  1895.   Start += RelativeMonth (Start, yyRelMonth);
  1896.  
  1897.   if (yyHaveDay && !yyHaveDate) {
  1898.     tod = RelativeDate (Start, yyDayOrdinal, yyDayNumber);
  1899.     Start += tod;
  1900.   }
  1901.  
  1902.   /* Have to do *something* with a legitimate -1 so it's distinguishable
  1903.    * from the error return value.  (Alternately could set errno on error.) */
  1904.   return Start == -1 ? 0 : Start;
  1905. }
  1906.  
  1907.  
  1908. #if    defined (TEST)
  1909.  
  1910. /* ARGSUSED */
  1911. int
  1912. main (ac, av)
  1913.     int        ac;
  1914.     char    *av[];
  1915. {
  1916.   char buff[MAX_BUFF_LEN + 1];
  1917.   time_t d;
  1918.  
  1919.   (void)printf ("Enter date, or blank line to exit.\n\t> ");
  1920.   (void)fflush (stdout);
  1921.  
  1922.   buff[MAX_BUFF_LEN] = 0;
  1923.   while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0]) {
  1924.     d = get_date (buff, (struct timeb *)NULL);
  1925.     if (d == -1)
  1926.       (void)printf ("Bad format - couldn't convert.\n");
  1927.     else
  1928.       (void)printf ("%s", ctime (&d));
  1929.     (void)printf ("\t> ");
  1930.     (void)fflush (stdout);
  1931.   }
  1932.   exit (0);
  1933.   /* NOTREACHED */
  1934. }
  1935. #endif    /* defined (TEST) */
  1936.